package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车接口")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result saveShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        return shoppingCartService.saveShoppingCart(shoppingCartDTO);
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result shoppingCartList(){
        return shoppingCartService.shoppingCartList();
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车中一个商品")
    public Result deleteOneShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        return shoppingCartService.deleteOneShoppingCart(shoppingCartDTO);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result cleanAllShoppingCart(){
        return shoppingCartService.cleanAllShoppingCart();
    }
}
